﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

namespace ItemComponent
{
    public class Move_Normal : MonoBehaviour
    {
        //目标点，出生点，初始方向
        protected Vector3 vTargetPos,vBornPos,vBornDir;
        //移动速度
        protected float fMoveSpeed;

        public virtual Vector3 MoveDir => vBornDir;

        public Move_Normal InitMoveData(Vector3 target, float speed)
        {
            vTargetPos = target;
            vBornPos = transform.position;
            vBornDir = (vTargetPos - vBornPos).normalized;
            fMoveSpeed = speed;
            return this;
        }

        public static Move_Normal AddComponent(GameObject obj, Vector3 target, float speed)
        {
            if (obj == null) return null;
            return obj.AddComponent<Move_Normal>().InitMoveData(target, speed);
        }

        protected virtual void Update()
        {
            Move(Time.deltaTime);
        }

        protected virtual void Move(float deltaTime)
        {
            transform.position += deltaTime * vBornDir * fMoveSpeed;
        }
    }

}